<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>File: README</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



  <div id="fileHeader">
    <h1>README</h1>
    <table class="header-table">
    <tr class="top-aligned-row">
      <td><strong>Path:</strong></td>
      <td>README
      </td>
    </tr>
    <tr class="top-aligned-row">
      <td><strong>Last Update:</strong></td>
      <td>Sat Jan 05 21:04:30 -0800 2008</td>
    </tr>
    </table>
  </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h1>Introducing Autocode</h1>
<p>
Autocode makes it relatively easy to automatically (re)load or even
generate classes and modules on the fly. You can use it like this:
</p>
<pre>
  require 'autocode'

  module Application
    extend Autoload
    autoload true
    directories :configurations, :models, :views, :controllers
  end
</pre>
<p>
This will attempt to load code dynamically from the given directories,
using the module name to determine which directory to look in. Thus,
<tt>Application::CustomerModel</tt> could load the file
<tt>models/customer_model.rb</tt>.
</p>
<h2>Reloading Code</h2>
<p>
To make code reloadable (very useful when debugging running processes),
simply extend <a href="../classes/Reloadable.html">Reloadable</a>. Thus,
our above example would become:
</p>
<pre>
  require 'autocode'

  module Application
    extend Autoload; extend Reloadable
    autoload true
    directories :configurations, :models, :views, :controllers
  end
</pre>
<p>
Then, later on, we can simply call <tt>Application.reload</tt> to reload
all the code that was loaded via <b>Autocode</b>. <b>Important</b>: Only
code loaded via <b>Autocode</b> (<a
href="../classes/Autoload.html">Autoload</a> or <a
href="../classes/Autocreate.html">Autocreate</a>) will be reloaded.
</p>
<h2>Autocreation</h2>
<p>
Sometimes it&#8216;s useful to generate defaults for classes or modules
that don&#8216;t exist. This can be particularly powerful when used in
combination with autoloading.
</p>
<pre>
  require 'autocode'

  module Application
    extend Autocreate; extend Reloadable
    [ [ :Configurations, :configurations ],
      [ :Models, :models ],
      [ :Views, :views ],
      [ :Controllers, :controllers ] ].each |mod_name, dir_name| do
      autocreate mod_name, Module.new do
        extend Autoload
        autoload true
        directories dir_name
      end
    end
  end
</pre>
<p>
This will autocreate the modules Configurations, Models, Views, and
Controllers within the Application module, as they are referenced, based on
the exemplar Module configured to autoload code from the configurations,
models, views, and controllers directories.
</p>
<p>
For example, referencing <tt>Application::Models::Customer</tt> will cause
the file <tt>models/customer.rb</tt> to be loaded.
</p>
<h2>Other Uses</h2>
<p>
Autoloading and autocreation, along with reloading, can be used to provide
sophisticated rules for loading and even generating modules and classes
within a given module. These capabilities are increasingly found within
frameworks like Rails and Camping, but <b>Autocode</b> makes it possible to
mixin these capabilities into any situation and precisely control how they
are applied.
</p>
<h2>Support</h2>
<p>
If you have questions or comments, please go to the <b>Autocode</b> Web
site first at <a
href="http://code.google.com/p/ruby-autocode">code.google.com/p/ruby-autocode</a>/.
</p>
<p>
(c) 2007 Dan Yoder
</p>
<p>
Licensed under the MIT License.
</p>

    </div>


   </div>


  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>